﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Week2EightBall
{
    
    public delegate void BallShowingMessageHandler(object sender, EventArgs e);
    
    public class EightBall
    {
        List<string> messages = new List<string>();

        public EightBall()
        {
            messages.Add("Maybe Later");
            messages.Add("Definitely");
            messages.Add("Not Now");
            messages.Add("Possibly");
            messages.Add("Abolutely Not");
        }
        
        private string message = String.Empty;
        public string Message
        {
            get
            {
                return message;
            }
        }

        public event BallShowingMessageHandler BallShowingEvent;

        public void ShakeBall()
        {
            //Put up a random message
            Random rand = new Random(DateTime.Now.Second);
            int messageNumber = rand.Next(0, messages.Count - 1);
            message = messages[messageNumber];

            //Wait a random amount of time before the message displays.
            if (BallShowingEvent != null)
            {
                System.Threading.Thread.Sleep(rand.Next(1000, 5000));
                BallShowingEvent(this, EventArgs.Empty);
            }
        }
    }
}
